/*
 * InfoLoadView.java
 */

package infoload;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import java.sql.*;
import java.util.logging.*;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

/**
 * The application's main frame.
 */
public class InfoLoadView extends FrameView {

    public InfoLoadView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = InfoLoadApp.getApplication().getMainFrame();
            aboutBox = new InfoLoadAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        InfoLoadApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea4 = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jTextField1 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jButton9 = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jButton10 = new javax.swing.JButton();
        jTextField6 = new javax.swing.JTextField();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(infoload.InfoLoadApp.class).getContext().getResourceMap(InfoLoadView.class);
        mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
        mainPanel.setName("mainPanel"); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel1.setName("jLabel1"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTable2.setBackground(resourceMap.getColor("jTable2.background")); // NOI18N
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Cliente_ID", "estado", "fecha", "hora", "comentarios"
            }
        ));
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane3.setViewportView(jTable2);
        jTable2.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable2.columnModel.title0")); // NOI18N
        jTable2.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable2.columnModel.title1")); // NOI18N
        jTable2.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable2.columnModel.title2")); // NOI18N
        jTable2.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable2.columnModel.title3")); // NOI18N
        jTable2.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable2.columnModel.title4")); // NOI18N
        jTable2.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable2.columnModel.title5")); // NOI18N

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jTextArea2.setName("jTextArea2"); // NOI18N
        jScrollPane4.setViewportView(jTextArea2);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 1066, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setBackground(resourceMap.getColor("jTable1.background")); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Nombe", "Apellidos", "Nick", "Password", "Fecha de alta", "Genero", "Email"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
        jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N
        jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N
        jTable1.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable1.columnModel.title4")); // NOI18N
        jTable1.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable1.columnModel.title5")); // NOI18N
        jTable1.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable1.columnModel.title6")); // NOI18N
        jTable1.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable1.columnModel.title7")); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextArea3.setColumns(20);
        jTextArea3.setRows(5);
        jTextArea3.setName("jTextArea3"); // NOI18N
        jScrollPane2.setViewportView(jTextArea3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1081, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        jTable3.setBackground(resourceMap.getColor("jTable3.background")); // NOI18N
        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "tipo", "nombre", "descripcion", "precio", "portable", "peso", "consumible", "cantidad"
            }
        ));
        jTable3.setName("jTable3"); // NOI18N
        jScrollPane6.setViewportView(jTable3);
        jTable3.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable3.columnModel.title0")); // NOI18N
        jTable3.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable3.columnModel.title1")); // NOI18N
        jTable3.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable3.columnModel.title2")); // NOI18N
        jTable3.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable3.columnModel.title3")); // NOI18N
        jTable3.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("jTable3.columnModel.title4")); // NOI18N
        jTable3.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("jTable3.columnModel.title5")); // NOI18N
        jTable3.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("jTable3.columnModel.title6")); // NOI18N
        jTable3.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("jTable3.columnModel.title7")); // NOI18N
        jTable3.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("jTable3.columnModel.title8")); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        jTextArea4.setColumns(20);
        jTextArea4.setRows(5);
        jTextArea4.setName("jTextArea4"); // NOI18N
        jScrollPane5.setViewportView(jTextArea4);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 1073, Short.MAX_VALUE)
                .addGap(21, 21, 21))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jScrollPane7.setName("jScrollPane7"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane7.setViewportView(jTextArea1);

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
        jTextField2.setName("jTextField2"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setName("jButton9"); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
        jTextField3.setName("jTextField3"); // NOI18N

        jTextField4.setText(resourceMap.getString("jTextField4.text")); // NOI18N
        jTextField4.setName("jTextField4"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jTextField5.setText(resourceMap.getString("jTextField5.text")); // NOI18N
        jTextField5.setName("jTextField5"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jButton10.setText(resourceMap.getString("jButton10.text")); // NOI18N
        jButton10.setName("jButton10"); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jTextField6.setText(resourceMap.getString("jTextField6.text")); // NOI18N
        jTextField6.setName("jTextField6"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton5))
                    .addComponent(jLabel4)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton6)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton8))
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 599, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addGap(16, 16, 16)
                                .addComponent(jButton4))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel10))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField6)
                            .addComponent(jTextField4)
                            .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))))
                .addGap(123, 123, 123))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jButton5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jButton6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jLabel5)
                    .addComponent(jButton8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4)
                            .addComponent(jLabel6)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(6, 6, 6)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(jButton9)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(jButton10))
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(279, 279, 279)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                .addGap(300, 300, 300))
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1329, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 387, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(infoload.InfoLoadApp.class).getContext().getActionMap(InfoLoadView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1359, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1189, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents


    
    
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    DefaultTableModel dtm;
    ArrayList cargar_cita=new ArrayList();

    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null); //fileChooser

    if (status == JFileChooser.APPROVE_OPTION) {

    File selectedFile =fileChooser.getSelectedFile();

    load_citas l=new load_citas();
    String direccion=selectedFile.getParent()+"/"+selectedFile.getName();

    cargar_cita=l.leer_archivo_exel(direccion);
    Iterator it=cargar_cita.iterator();

    try{
        
    Object datos[] = new Object [10];
    dtm = (DefaultTableModel) jTable2.getModel();
    for (int i = jTable2.getRowCount() - 1; i>=0; i--)
    {
    dtm.removeRow(i);
    } 

    while(it.hasNext()){

    citas citas_ing;
    citas_ing=(citas) it.next();
    
    datos[0]=citas_ing.getID();
    datos[1]=citas_ing.getCliente_ID();
    datos[2]=citas_ing.getEstado();
    datos[3]=citas_ing.getFecha();
    datos[4]=citas_ing.getHora();
    datos[5]=citas_ing.getCometarios();


    dtm.addRow(datos);
    
    // Insertar citas en la base de datos
        String connURL= "jdbc:mysql://localhost:3306/bysDB";
        Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
    try
       {
           Statement stmt = conn.createStatement();
           
           
           System.out.println("Estos son los datos a introducir en la BBDD: ");
           System.out.println("--------------------------------------------");
           for (int i = 0; i < 6; i++) {
               System.out.println(datos[i]);
           }
         
           //String sentencia = "INSERT INTO `bysDB`.`cita` (ID,Cliente_ID,estado,fecha,hora,comentarios) VALUES ("+datos[0]+","+datos[1]+",'"+datos[2]+"','"+datos[3]+"','"+datos[4]+"','"+datos[5]+"')";

           String sentencia = "INSERT INTO `bysDB`.`cita` (ID,Cliente_ID,estado,fecha,hora,comentarios)"
                   + " SELECT "+datos[0]+","+datos[1]+",'"+datos[2]+"','"+datos[3]+"','"+datos[4]+"','"+datos[5]+"' FROM dual "
                   + "WHERE NOT EXISTS (SELECT * FROM `bysDB`.`cita` WHERE ID = "+datos[0]+")";

           stmt.executeUpdate(sentencia);

           if (stmt != null) stmt.close();
           if (conn != null)conn.close();


        } catch (Exception e) {
            Logger.getLogger("Guardado en").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());

            System.out.println("Se ha producido un Error al introducir los datos en la BBDD");
            jTextArea2.append("Se ha producido un Error!");
            jTextArea2.append(System.getProperty("line.separator"));

        }
    
    
    
    //Fin insertar citas en la base de datos
    
    
    
    }
                jTextArea2.append("Los nuevos datos se han");
            jTextArea2.append(System.getProperty("line.separator"));
            jTextArea2.append("introducido en la BD");           
            jTextArea2.append(System.getProperty("line.separator"));
    jTextArea2.append("Numero de registros en la BBDD: "+jTable2.getRowCount());
    jTextArea2.append(System.getProperty("line.separator"));

    
    } catch(Exception e){
    //manejo de error
    }

    } else if (status == JFileChooser.CANCEL_OPTION) {

    System.out.println("cancelado");

    }
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    DefaultTableModel dtm;
    ArrayList cargar_cliente=new ArrayList();

    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null); //fileChooser

    if (status == JFileChooser.APPROVE_OPTION) {

    File selectedFile =fileChooser.getSelectedFile();

    load_clientes l=new load_clientes();
    String direccion=selectedFile.getParent()+"/"+selectedFile.getName();

    cargar_cliente=l.leer_archivo_exel(direccion);
    Iterator it=cargar_cliente.iterator();

    try{
        
    Object datos[] = new Object [10];
    dtm = (DefaultTableModel) jTable1.getModel();
    for (int i = jTable1.getRowCount() - 1; i>=0; i--)
    {
    dtm.removeRow(i);
    } 

    while(it.hasNext()){

    cliente cli;
    cli=(cliente) it.next();
    
    datos[0]=cli.getID();
    datos[1]=cli.getNombre();
    datos[2]=cli.getApellidos();
    datos[3]=cli.getNick();
    datos[4]=cli.getPassword();
    datos[5]=cli.getFecha_alta();
    datos[6]=cli.getGenero();
    datos[7]=cli.getEmail();


    dtm.addRow(datos);
    
    // Insertar clientes en la base de datos
        String connURL= "jdbc:mysql://localhost:3306/bysDB";
        Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
    try
       {
           Statement stmt = conn.createStatement();
           
           
           System.out.println("Estos son los datos a introducir en la BBDD: ");
           System.out.println("--------------------------------------------");
           for (int i = 0; i < 8; i++) {
               System.out.println(datos[i]);
           }

           //String sentencia = "INSERT INTO `bysDB`.`cliente` (ID,nombre,apellido,nick,password,fecha_alta,genero,email) VALUES ("+datos[0]+",'"+datos[1]+"','"+datos[2]+"','"+datos[3]+"','"+datos[4]+"','"+datos[5]+"','"+datos[6]+"','"+datos[7]+"')";
           String sentencia = "INSERT INTO `bysDB`.`cliente` (ID,nombre,apellido,nick,password,fecha_alta,genero,email)"
                   + " SELECT "+datos[0]+",'"+datos[1]+"','"+datos[2]+"','"+datos[3]+"','"+datos[4]+"','"+datos[5]+"',"
                   + "'"+datos[6]+"','"+datos[7]+"' FROM dual "
                   + "WHERE NOT EXISTS (SELECT * FROM `bysDB`.`cliente` WHERE ID = "+datos[0]+")";

           stmt.executeUpdate(sentencia);

           if (stmt != null) stmt.close();
           if (conn != null)conn.close();


        } catch (Exception e) {
            Logger.getLogger("Guardado en").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());

            System.out.println("Se ha producido un Error al introducir los datos en la BBDD");
            jTextArea3.append("Se ha producido un Error!");
            jTextArea3.append(System.getProperty("line.separator"));
        }
    
    
    
    //Fin insertar clientes en la base de datos
    
    }
                    jTextArea3.append("Los nuevos datos se han");
            jTextArea3.append(System.getProperty("line.separator"));
            jTextArea3.append("introducido en la BD");           
            jTextArea3.append(System.getProperty("line.separator"));
    jTextArea3.append("Numero de registros introducidos en la BBDD: "+jTable1.getRowCount());
    jTextArea3.append(System.getProperty("line.separator"));
    
    } catch(Exception e){
    //manejo de error
    }

    } else if (status == JFileChooser.CANCEL_OPTION) {

    System.out.println("cancelado");

    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    DefaultTableModel dtm;
    ArrayList cargar_producto=new ArrayList();

    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null); //fileChooser

    if (status == JFileChooser.APPROVE_OPTION) {

    File selectedFile =fileChooser.getSelectedFile();

    load_productos l=new load_productos();
    String direccion=selectedFile.getParent()+"/"+selectedFile.getName();

    cargar_producto=l.leer_archivo_exel(direccion);
    Iterator it=cargar_producto.iterator();

    try{
        
    Object datos[] = new Object [10];
    dtm = (DefaultTableModel) jTable3.getModel();
    for (int i = jTable3.getRowCount() - 1; i>=0; i--)
    {
    dtm.removeRow(i);
    } 

    while(it.hasNext()){

    producto producto_ing;
    producto_ing=(producto) it.next();
    
    datos[0]=producto_ing.getID();
    datos[1]=producto_ing.getTipo();
    datos[2]=producto_ing.getNombre();
    datos[3]=producto_ing.getDescripcion();
    datos[4]=producto_ing.getPrecio();
    datos[5]=producto_ing.getPortable();
    datos[6]=producto_ing.getPeso();
    datos[7]=producto_ing.getConsumible();
    datos[8]=producto_ing.getCantidad();


       
    
    dtm.addRow(datos);
    
    // Insertar recursos en la base de datos
        String connURL= "jdbc:mysql://localhost:3306/bysDB";
        Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
    try
       {
           Statement stmt = conn.createStatement();
           
           
           System.out.println("Estos son los datos a introducir en la BBDD: ");
           System.out.println("--------------------------------------------");
           for (int i = 0; i < 8; i++) {
               System.out.println(datos[i]);
           }

           //String sentencia = "INSERT INTO `bysDB`.`recurso` (ID,tipo,nombre,descripcion,precio,portable,peso,consumible,cantidad)"
           //        + " VALUES ("+datos[0]+",'"+datos[1]+"','"+datos[2]+"','"+datos[3]+"',"+datos[4]+",'"+datos[5]+"',"+datos[6]+",'"+datos[7]+"',"+datos[8]+")";
           
           
           String sentencia = "INSERT INTO `bysDB`.`recurso` (ID,tipo,nombre,descripcion,precio,portable,peso,consumible,cantidad)"
                   + " SELECT "+datos[0]+",'"+datos[1]+"','"+datos[2]+"','"+datos[3]+"',"+datos[4]+",'"+datos[5]+"',"+datos[6]+",'"+datos[7]+"',"+datos[8]+" FROM dual "
                   + "WHERE NOT EXISTS (SELECT * FROM `bysDB`.`recurso` WHERE ID = "+datos[0]+")";
           stmt.executeUpdate(sentencia);

           
           if (stmt != null) stmt.close();
           if (conn != null)conn.close();


        } catch (Exception e) {
            Logger.getLogger("Guardado en").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
                jTextArea4.append("Los nuevos datos se han");
            jTextArea4.append(System.getProperty("line.separator"));
            jTextArea4.append("introducido en la BD");           
            jTextArea4.append(System.getProperty("line.separator"));
            System.out.println("Se ha producido un Error al introducir los datos en la BBDD");
            jTextArea4.append("Se ha producido un Error!");
            jTextArea4.append(System.getProperty("line.separator"));

        }
    
    
    
    //Fin insertar recursos en la base de datos
    
    }
    jTextArea4.append("Numero de registros introducidos en la BBDD: "+jTable3.getRowCount());
    
    } catch(Exception e){
    //manejo de error
    }

    } else if (status == JFileChooser.CANCEL_OPTION) {

    System.out.println("cancelado");

    }
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        //CLIENTES
        int ID = 0;        
        String nombre;
        String apellido;
        String nick;
        String password;
        String fecha_alta;
        String genero;
        String email;

       try
       {
           String connURL= "jdbc:mysql://localhost:3306/bysDB";
           Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
           

           
           Statement stmt = conn.createStatement();
           
           ResultSet rset = stmt.executeQuery("SELECT * FROM `bysDB`.`cliente`");
           
           
           while (rset.next()){
               ID = rset.getInt("ID"); 
               nombre = rset.getString("nombre");
               apellido = rset.getString("apellido");
               nick = rset.getString("nick");
               password = rset.getString("password");
               fecha_alta = rset.getString("fecha_alta");
               genero = rset.getString("genero");
               email = rset.getString("email");
               System.out.println(ID + nombre + apellido + nick + password + fecha_alta + genero + email);
               jTextArea1.append(ID+" "+nombre+" "+apellido+" "+nick+" "+password+" "+fecha_alta+" "+genero+" "+email);
               jTextArea1.append(System.getProperty("line.separator"));

           }
           
           if(rset != null) rset.close();
           if(stmt != null) stmt.close();
           if(conn != null) conn.close();

        } catch (Exception e) {
            Logger.getLogger("Recuperar ID").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
        }
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
    jTextArea1.setText("");
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        //CITAS
        int ID = 0;        
        int Cliente_ID;
        String estado;
        String fecha;
        String hora;
        String comentarios;

       try
       {
           String connURL= "jdbc:mysql://localhost:3306/bysDB";
           Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
           

           
           Statement stmt = conn.createStatement();
           
           ResultSet rset = stmt.executeQuery("SELECT * FROM `bysDB`.`cita`");
           
           
           while (rset.next()){
               ID = rset.getInt("ID"); 
               Cliente_ID = rset.getInt("Cliente_ID");
               estado = rset.getString("estado");
               fecha = rset.getString("fecha");
               hora = rset.getString("hora");
               comentarios = rset.getString("comentarios");
               
               System.out.println(ID + Cliente_ID + estado + fecha + hora + comentarios);
               jTextArea1.append(ID+" "+Cliente_ID+" "+estado+" "+fecha+" "+hora+" "+comentarios);
               jTextArea1.append(System.getProperty("line.separator"));

           }
           
           if(rset != null) rset.close();
           if(stmt != null) stmt.close();
           if(conn != null) conn.close();

        } catch (Exception e) {
            Logger.getLogger("Recuperar ID").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
        }
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        //Recursos
        int ID = 0;        
        String tipo;
        String nombre;
        String descripcion;
        int precio;
        String portable;
        int peso;
        String consumible;
        int cantidad;

       try
       {
           String connURL= "jdbc:mysql://localhost:3306/bysDB";
           Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
           

           
           Statement stmt = conn.createStatement();
           
           ResultSet rset = stmt.executeQuery("SELECT * FROM `bysDB`.`recurso`");
           
           
           while (rset.next()){
               ID = rset.getInt("ID"); 
               tipo = rset.getString("tipo");
               nombre = rset.getString("nombre");
               descripcion = rset.getString("descripcion");
               precio = rset.getInt("precio");
               portable = rset.getString("portable");
               peso = rset.getInt("peso");
               consumible = rset.getString("consumible");
               cantidad = rset.getInt("cantidad");
               
               System.out.println(ID + tipo + nombre + descripcion + precio + portable + peso + consumible + cantidad);
               jTextArea1.append(ID+" "+tipo+" "+nombre+" "+descripcion+" "+precio+" "+portable+" "+peso+" "+consumible+" "+cantidad);
               jTextArea1.append(System.getProperty("line.separator"));
           }
           
           if(rset != null) rset.close();
           if(stmt != null) stmt.close();
           if(conn != null) conn.close();

        } catch (Exception e) {
            Logger.getLogger("Recuperar ID").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
        }
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    //GUARDAR BASE DE DATOS EN UN EXCEL
     //CLiente
       try
       {
           String connURL= "jdbc:mysql://localhost:3306/bysDB";
           Connection conn = DriverManager.getConnection(connURL,"bys-dba","password");
           Statement stmt = conn.createStatement();
           /*
            * INTO OUTFILE: se indicará el directorio y archivo donde se guardan.
            FIELDS TERMINATED BY: separador que utilizaremos para los campos.
            ENCLOSED BY: delimitador utilizado para cada campo.
            LINES TERMINATED BY: separador que utilizaremos para indicar el fin de línea.
            */
           stmt.executeQuery("SELECT * FROM `bysDB`.`cliente`"
                   + " INTO OUTFILE '/"+jTextField1.getText()+".csv' "
                   + "FIELDS TERMINATED BY ';' "
                   + "ENCLOSED BY ' ' "
                     +"LINES TERMINATED BY 'END LINE'");
           jTextField3.setText("Fichero guardado!");
           if(stmt != null) stmt.close();
           if(conn != null) conn.close();

        } catch (Exception e) {
            Logger.getLogger("Recuperar ID").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
            jTextField3.setText("Error al guardar!");
        }
  
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
//GUARDAR BASE DE DATOS EN UN EXCEL
     //Citas
       try
       {
           String connURL= "jdbc:mysql://localhost:3306/bysDB";
           Connection conn = DriverManager.getConnection(connURL,"root","tintin");//"bys-dba","password");
           Statement stmt = conn.createStatement();
           /*
            * INTO OUTFILE: se indicará el directorio y archivo donde se guardan.
            FIELDS TERMINATED BY: separador que utilizaremos para los campos.
            ENCLOSED BY: delimitador utilizado para cada campo.
            LINES TERMINATED BY: separador que utilizaremos para indicar el fin de línea.
            */
           stmt.executeQuery("SELECT * FROM `bysDB`.`cita`"
                   + " INTO OUTFILE '/"+jTextField2.getText()+".csv' "
                   + "FIELDS TERMINATED BY ';' "
                   + "ENCLOSED BY ' ' "
                     +"LINES TERMINATED BY 'END LINE'");
           jTextField4.setText("Fichero guardado!");

           if(stmt != null) stmt.close();
           if(conn != null) conn.close();

        } catch (Exception e) {
            Logger.getLogger("Recuperar ID").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
            jTextField3.setText("Error al guardar!");
        }
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
//GUARDAR BASE DE DATOS EN UN EXCEL
     //recursos
       try
       {
           String connURL= "jdbc:mysql://localhost:3306/bysDB";
           Connection conn = DriverManager.getConnection(connURL,"root","tintin");//"bys-dba","password");
           Statement stmt = conn.createStatement();
           /*
            * INTO OUTFILE: se indicará el directorio y archivo donde se guardan.
            FIELDS TERMINATED BY: separador que utilizaremos para los campos.
            ENCLOSED BY: delimitador utilizado para cada campo.
            LINES TERMINATED BY: separador que utilizaremos para indicar el fin de línea.
            */
           stmt.executeQuery("SELECT * FROM `bysDB`.`recurso`"
                   + " INTO OUTFILE '/"+jTextField5.getText()+".csv' "
                   + "FIELDS TERMINATED BY ';' "
                   + "ENCLOSED BY ' ' "
                     +"LINES TERMINATED BY 'END LINE'");
           jTextField6.setText("Fichero guardado!");

           if(stmt != null) stmt.close();
           if(conn != null) conn.close();

        } catch (Exception e) {
            Logger.getLogger("Recuperar ID").log(Level.SEVERE, "ERROR: " + e.getLocalizedMessage());
            jTextField6.setText("Error al guardar!");
        }
}//GEN-LAST:event_jButton10ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextArea jTextArea3;
    private javax.swing.JTextArea jTextArea4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;



}
